<?php
header("content-type:text/html;charset=utf8");
$pdo =new PDO("mysql:host=127.0.0.1;dbname=1117;charset=utf8","root","root");
$sql = "select * from shop";
$res = $pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);
//print_r($res);die;

?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<center>
    <table border="1">
        <tr>
            <td>商品图片</td>
            <td>名称</td>
            <td>价格</td>
            <td>库存</td>
            <td>操作</td>

        </tr>
        <?php foreach ($res as $v) {?>
        <tr>
            <td><img src="./img/img.png" style="width: 100px;height: 100px"></td>
            <td><?php echo $v['name']?></td>
            <td><?php echo $v['price']?></td>
            <td><?php echo $v['stock']?></td>
            <td><input type="button" value="抢购" class="btn" data-id="<?php echo $v['shop_id']?>"></td>

        </tr>
        <?php }?>
    </table>
</center>
</body>
</html>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
    $(".btn").click(function(){
        var shop_id = $(this).attr("data-id");
        // alert(shop_id);
        $.ajax({
            url:"qing.php",
            data:{shop_id:shop_id},
            type:"post",
            dataType:"json",
            success:function (res) {
                alert(res.msg);
                location.reload();
            }
        })
    })
</script>
